#include "dialogslaveparamwrite.h"
#include "ui_dialogslaveparamwrite.h"

DialogSlaveParamWrite::DialogSlaveParamWrite(QWidget *parent, const QString &ctx1, const QString &ctx2) :
        QDialog(parent),
        ui(new Ui::DialogSlaveParamWrite)
{
    ui->setupUi(this);
    numberkeyboard = new DialogVKB(this);
    ui->lineEditStartID->setText(ctx1);
    ui->lineEditEndID->setText(ctx2);

    //将所有lineedit信号都和软件盘界面显示关联
    connect(ui->lineEditStartID, SIGNAL(send_show(QString)), this, SLOT(show_numberkeyboard_ui(QString)));
    connect(ui->lineEditEndID, SIGNAL(send_show(QString)), this, SLOT(show_numberkeyboard_ui(QString)));
    connect(numberkeyboard, SIGNAL(sendMessage(QString)), this, SLOT(confirmString(QString)));
}

DialogSlaveParamWrite::~DialogSlaveParamWrite()
{
    delete ui;
}

void DialogSlaveParamWrite::getInputValue(int &x, int &y)
{
    x = ui->lineEditStartID->text().toInt();
    y = ui->lineEditEndID->text().toInt();
}

void DialogSlaveParamWrite::show_numberkeyboard_ui(const QString &data)
{
    lineEdit_object = sender()->objectName();//获得调用软件盘的部件的名称
    numberkeyboard->setInputdata(data);
    numberkeyboard->show();
}

void DialogSlaveParamWrite::confirmString(const QString &gemfield)
{
    //判断应该将信息写入哪一个输入框
    if (lineEdit_object == ui->lineEditStartID->objectName())
    {
        ui->lineEditStartID->setText(gemfield);
    }
    else if (lineEdit_object == ui->lineEditEndID->objectName())
    {
        ui->lineEditEndID->setText(gemfield);
    }
}
